<?php
namespace Home\Controller;
use Common\Controller\AuthController;
class FlController extends AuthController {
    public function index(){//显示分析信息
		$Fl = M("Fl");
		$count = $Fl->count();
		$Page = new \Think\Page($count,10);
		$show = $Page->show();
		$list = $Fl->limit($Page->firstRow.','.$Page->listRows)->order('flpx asc')->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
    }
    public function add(){//增加分类
		$this->display();
    }
    public function addtj(){//提交增加分类
		if(IS_POST){
			$Fl = D("Fl");
			if(!$Fl->create($_POST,4)){
				$error = $Fl->getError();
				$this->error($error,U('Fl/index'));
			}else{
				$Fl->create();
				$result = $Fl->add();
				if($result){
					$this->success("分类添加成功！",U('Fl/index'),1);
				}else{
					$this->error("分类添加失败！",U('Fl/index'),1);
				}
			}
		}else{
			$this->error("操作有误！",U('Fl/index'));
		}
    }
    public function flbj($id){//编辑分类
		$Fl = M(Fl);
		$map['id'] = $id;
		$result = $Fl->where($map)->find();
		$this->assign('result',$result);
		$this->display();
    }
    public function flbjtj(){//提交编辑分类
		if(IS_POST){
			$Fl = D("Fl");
			if(!$Fl->create($_POST,4)){
				$error = $Fl->getError();
				$this->error($error,U('Fl/flbj',array('id'=>$_POST['id'])));
			}else{
				$where['id'] = $_POST['id'];
				$result = $Fl->where($where)->save();
				if($result){
					$this->success("分类修改成功！",U('Fl/index'),1);
				}else{
					$this->error("分类修改失败！",U('Fl/flbj',array('id'=>$_POST['id'])),1);
				}
			}
		}else{
			$this->error("分类修改失败！！",U('Fl/index'),1);
		}
    }
	public function delete($id){//删除分类
		$Fl = M(Fl);
		$map['id'] = $id;
		$result = $Fl->where($map)->delete();
		if($result){
			$this->success("分类删除成功！",U('Fl/index'),1);
		}else{
			$this->error("分类删除失败！",U('Fl/index'),1);
		}
    }
}